<?php
/**
 * MostRead
 * @使用地方：新频道页MostRead
 * <controller data='{"id":342,"topTagId":"310","limit":"5"}'>
 */
namespace haibao\cms\business\control\pc\channel;
use \haibao\cms\business\control\pc\entity\ArticleEntity;

class MostReadcontroller extends ChannelController{
	

	public function __construct($updateTime = null,$controlId,$isPublish){
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	/**
	 * 显示模版内容（模版动态数据的绑定和模版输出）
	 * @param : String $content
	 * @param : Array $controlData;
	 */
	public function displayTemplateHtml(){

		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		
		
		$this->getMostReadData($controlData['manual']);
		
		$path = $this->generateHtmlPath(__CLASS__);
		$isNewHtml = $this->generateHtml($path,$content);
		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);
		return $content;
	}
	
	
	/**
	 * 调用拥有该?标签，前?天浏览量最高，?级及以上的?条资讯和图集
	 */
	public function getMostReadData($dataCondition){
		
		$articleEntity = new ArticleEntity();
		$articleEntity->setLevel(3);
		$articleEntity->setBigLevel(7);
		$articleEntity->setLimit($dataCondition['limit']);
		$articleEntity->setIsProImage(false);
		$articleEntity->setIsLeftJoinTag(true);
		$articleEntity->setIsConditionTag(true);
		$articleEntity->setIsReturnTag(false);
		$articleEntity->setIsImageColl(true);
		$articleEntity->setSource(__CLASS__.$dataCondition['topTagId']);
		$articleEntity->setIsDebug(false);
		$articleEntity->setIsOnlyReturnPrimaryTag(false);
		$articleEntity->setIsPrimaryTag(true);
		$articleEntity->setIsParentTag(true);
		$articleEntity->setTagIds((int)$dataCondition['topTagId']);
		$articleEntity->setOrderByClick(true);
		$articleEntity->setOrderByNew(false);
 		if($dataCondition['topTagId'] == 211 || $dataCondition['topTagId'] == 520){
 		    //新娘 生活 频道  mostread 读两周的资讯
 		    $articleEntity->setIsDate(true, \haibao\cms\business\control\pc\action\ArticleAction::DATE_TYPE_HALFWEEK);
 		}else{
		    $articleEntity->setIsDate(true, \haibao\cms\business\control\pc\action\ArticleAction::DATE_TYPE_WEEK);
		}
		$this->articleAction->setArticleEnity($articleEntity);
		list($articles,$imageColls) = $this->articleAction->getListForNew();
		$mergeData = $this->mergeData($articles['list'],$imageColls['list'],$dataCondition['limit']);
		$mostReadList = array();
	    foreach($mergeData as $data){
	        $temp = array();
	        if($data->SiteType == \haibao\cms\business\control\pc\action\ArticleAction::INFO_TYPE_ARTICLE){
	            $temp['Channel'] = self::getArticleUrl($data->PublishId,$data->ArticleTag->ParentId);
	        }else{
	            $temp['Channel'] = self::getArticleUrl($data->Id,$data->ImageCollectiveTag->ParentId,\haibao\cms\business\control\pc\action\ArticleAction::INFO_TYPE_IMAGE);
	        }
	        $temp['Id'] = $data->Id;
	        $temp['Title'] = $data->Title;
	        $temp['ShortTitle'] = $data->ShortTitle?$data->ShortTitle:$data->Title;
	        $temp['SiteType'] = $data->SiteType;
	        array_push($mostReadList,$temp);
	    }
		$this->assign('mostReadList',$mostReadList);
	}
}